package com.agv.backend.service.impl;

import com.agv.backend.entity.pojo.AgvFlaw;
import com.agv.backend.mapper.AgvFlawMapper;
import com.agv.backend.service.AgvFlawService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


@Service
@Slf4j
public class AgvFlawServiceImpl extends ServiceImpl<AgvFlawMapper, AgvFlaw> implements AgvFlawService{

    private final AgvFlawMapper agvFlawMapper;

    public AgvFlawServiceImpl(AgvFlawMapper agvFlawMapper) {
        this.agvFlawMapper = agvFlawMapper;
    }

    @Override
    public List<AgvFlaw> listFlaw(AgvFlaw entity) {
        QueryWrapper<AgvFlaw> queryWrapper = new QueryWrapper<>();
        return agvFlawMapper.selectList(queryWrapper);
    }

    @Override
    public AgvFlaw getFlaw(Long id){
        return agvFlawMapper.selectById(id);
    }

    @Override
    public int addFlaw(AgvFlaw entity) {
        entity.setShown(false);
        entity.setCreateTime(new Date());
        return agvFlawMapper.insert(entity);
    }

    @Override
    public int updateFlaw(AgvFlaw entity) {
        return agvFlawMapper.updateById(entity);
    }

    @Override
    public int delFlaw(Long id) {
        return agvFlawMapper.deleteById(id);
    }

    @Override
    public List<AgvFlaw> liveInfo(Long id) {
        return agvFlawMapper.getLiveInfo(id);
    }

    @Override
    public int checkAllConfirmed(Long id) {
        return agvFlawMapper.checkAllConfirmed(id);
    }

    @Override
    public List<AgvFlaw> getFlawsByTime(String startTime, String endTime) {
        return agvFlawMapper.selectList(new QueryWrapper<AgvFlaw>().between("create_time", startTime, endTime));
    }


}
